/**
 * Created by Administrator on 2017/7/21.
 */


$(function () {

            //    nav
    var s = location.href;
    s=s.replace(/\?.*$/,'');
    s=s.replace(/^.*\//,'');
    var arr = $(".nav-list li a");
    var i = 0;
    for(i;i<arr.length;i++){
        var url = $(arr[i]).attr("href");
        if( url == s){
            if(i == 0 || i == 1){
                $(arr[i].parentNode).addClass("nav-active");
            }else {
                $(arr[i].parentNode).addClass("nav-li-active");
                $(arr[i].parentNode.parentNode.parentNode).addClass("nav-active");
            }
        }
    }

            // keywords swiper

    var stt = '<div class="swiper-slide"><span class="img-number">11</span><img src="images/app1.png"></div>' +
        '<div class="swiper-slide"><span class="img-number">12</span><img src="images/app2.png"></div>' +
        '<div class="swiper-slide"><span class="img-number">13</span><img src="images/app3.png"></div>' +
        '<div class="swiper-slide"><span class="img-number">14</span><img src="images/app4.png"></div>' +
        '<div class="swiper-slide"><span class="img-number">15</span><img src="images/app5.png"></div>' +
        '<div class="swiper-slide"><span class="img-number">16</span><img src="images/app6.png"></div>' +
        '<div class="swiper-slide"><span class="img-number">7</span><img src="images/app7.png"></div>';


    $(".data").click(function () {
        var h = $(this).parent().height();
        if( h <= 42){
            $(this).children(".dec").css({transform:"rotate(-180deg)"});
            $(this).next().animate({height:"140px"},300);
            $(this).next().children(".swiper-container").animate({height:"140px"});
            $(this).next().css({margin:"0 30px",borderTop:"1px solid #eeeeee"});

            $(this).next().find(".swiper-wrapper").append(stt);

            var index = $(".data").index($(this)) + 1;
            $(this).next().children(".swiper-container").addClass("swiper-container"+index);
            var mySwiper = new Swiper( '.swiper-container' + index,{
                pagination: '.swiper-pagination',
                loop:false,
                grabCursor: true,
                onlyExternal:true,
                paginationClickable: true,
                slidesPerGroup:10,
                slidesPerView:10,
                autoplayDisableOnInteraction:true,
                autoplay: false
            });
            $(this).next().children(".swiper-container").children('.swiper-button-prev').on('click', function(e){
                e.preventDefault();
                mySwiper.swipePrev()
            });
            $(this).next().children(".swiper-container").children('.swiper-button-next').on('click', function(e){
                e.preventDefault();
                mySwiper.swipeNext()
            });
        }else{
            $(this).next().animate({height:"0"},300);
            $(this).next().children(".swiper-container").animate({height:"0"},300);
            $(this).next().css({margin:"0 30px 0 30px",borderTop:"1px solid #fff"});
            $(this).children(".dec").css({transform:"rotate(-360deg)"});
        }
    });

            //    textarea copy , search , empty event
    $(".sear").click(function () {
        var search = $(".search-key").val();
    });

    $(".copy").click(function () {
        var copy = $(".search-key").val();
        $(this).css({background:"#ccc"});
        $(this).html("Copy Successful");
        setTimeout(function () {
            $(".copy").css({background:"#f9f9f9"}).html("Copy").mouseenter(function () {
                $(this).css({background:"#ccc"});
            }).mouseleave(function () {
                $(this).css({background:"#f9f9f9"});
            });
        },1000);
    });

    $(".empty").click(function () {
       $(".search-key").val("");
    });

            //    e-mail test
    $(".email").blur(function () {
        if( this.value=="" || ( this.value!="" && !/.+@.+\.[a-zA-Z]{2,4}$/.test(this.value) ) ){
            var errorMsg = 'Please enter the correct e-mail address.';
            $(".formtips").html(errorMsg);
            $(".tips").css({display:"block"});
        }else{
            var okMsg = 'Entered correctly.';
            $(".formtips").html(okMsg);
        }
    });

            //  footer e-mail
    $(".contact-as .inp").blur(function () {
        var text = $(".inp").val();
        if(text=="" || ( text!="" && !/.+@.+\.[a-zA-Z]{2,4}$/.test(this.value) )){
            $(".contact-as .a").click(function () {
                $(".contact-as .inp").focus();
                return false;
            });
        }else{
            $(".contact-as .a").click(function () {
                return true;
            })
        }
    });

            //    title select
    $(".search-word input").keyup(function () {
        $(".title-hide").css({display:"block"});
        $(".title-list p").css({display:"none"});
        var txt = $(this).val();
        var list = $(".title-list li");
        var i = 0 , t = 0, len = list.length;
        $(".title-list li").click(function () {
           $(".search-word input").val($(this).html());
            $(".title-hide").css({display:"none"});
        });
        if(txt == ""){
            $(".title-hide").css({display:"none"});
        }
        for(i; i<len; i++){
            var tit = $(list[i]).html();
            var con = tit.indexOf(txt);
            if(con == -1){
                t++;
                $(list[i]).css({display:"none"});
                if( t == len){
                    $(".title-list p").css({display:"block"});
                }
            }else{
                $(list[i]).css({display:"block"});
            }
        }
    })
});
